<?php

function pp($data) {
    echo '<pre>';
    print_r($data);
    echo '<pre>';
    die;
}

function p($data) {
    echo '<pre>';
    print_r($data);
    echo '<pre>';
}

//递归目录显示
function recursive_directory($dir = '') {
    if (empty($dir)) {
        $dir = './';
    }

    $dir_array = array();
    $file = new \FilesystemIterator($dir, \FilesystemIterator::CURRENT_AS_FILEINFO);
//    $file = new \FilesystemIterator($dir);

    foreach ($file as $k => $v) {

        if ($file->isDir()) {
            $path = $v->getFilename();
            $dir_array[$k]['child'] = recursive_directory("$dir/$path/");
            $dir_array[$k]['name'] = $v->getFilename();
            $dir_array[$k]['is_dir'] = 1;
        } else {
            $dir_array[$k]['is_dir'] = 0;
            $dir_array[$k]['name'] = $v->getFilename();
        }
    }
    return $dir_array;
}

/**
 * 格式化时间戳，精确到毫秒，x代表毫秒
 *
 * YmdHisx 20161124134129036
 *
 * YmdHis x 20161124134129 036
 * 
 */
function microtime_format($tag, $time) {
    list($usec, $sec) = explode(".", $time);
    $date = date($tag, $usec);
    return str_replace('x', $sec, $date);
}
